package com.leaves.sys.config;

import com.leaves.core.properties.ThreadProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;

import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @Author Chenweiwei
 * @Date 2021/9/10 14:51
 * @Version 1.0
 */
@Configuration
public class ThreadConfig {

    @Autowired
    ThreadProperties threadProperties;


    /**
     * 执行周期性或定时任务
     */
    @Bean(name = "scheduledThreadPoolExecutor")
    protected ScheduledThreadPoolExecutor scheduledThreadPoolExecutor() {
       return new ScheduledThreadPoolExecutor(threadProperties.getCorePoolSize(), new ScheduledExecutorFactoryBean());
    }
}
